package com.jservice.web.smkAd;

import com.jservice.framework.dto.Pageable;
import com.jservice.framework.dto.Pager;
import com.jservice.framework.idWorker.Sequence;
import com.jservice.framework.spring.SpringContextUtil;
import com.jservice.model.SmkAd;
import com.jservice.web.base.JBaseService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;

/**
 * SmkBannerService
 *
 * @Author cwledit
 * @DATE 2017/6/12.
 */
@Service("smkAdService")
@Transactional(readOnly = true)
public class SmkAdService extends JBaseService {

    public static final SmkAd DAO = new SmkAd();

    public static SmkAdService me() {
        return SpringContextUtil.getBean("smkAdService");
    }

    @Resource
    private Sequence idWorker;

    public Pager findPage(Pageable pageable) {
        return findPage(pageable,DAO, DAO.TABLE_NAME);
    }

    public SmkAd findById(String bannerId){
        return DAO.findById(bannerId);
    }

    @Transactional(readOnly = false)
    public boolean save(SmkAd smkAd) {

        smkAd.setId(idWorker.nextIdStr());
        smkAd.setCreateDate(new Date());
        smkAd.setModifyDate(new Date());

        return smkAd.save();
    }

    @Transactional(readOnly = false)
    public boolean update(SmkAd smkAd) {
        smkAd.setModifyDate(new Date());
        return smkAd.update();
    }

}
